package main;

import graphics.GraphicModule;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSplitPane;

import access.Request_Types;
import connections.Interface;

@SuppressWarnings("serial")
public class Driver extends JFrame implements MouseListener, MouseMotionListener {
	
	//TODO split main window and console operations into different threads
//	Thread Main;
//	Thread Secondary;
	
	/**
	 * @param AllNodess
	 * <p>This vector holds all the different nodes in the network.
	 * <p>Interface = Node
	 */
	Vector<Interface> AllNodes = new Vector<Interface>();
	
	/**
	 * @param GM
	 * <p>This class handles all the drawing for each node. <p>It holds all of the different methods
	 * and each node is passed to it.  <p>The module can accept a node and a link class and uses
	 * internal parameters to draw it.
	 */
	GraphicModule GM = new GraphicModule();
	
	/**
	 * @param mainView
	 * <p>This is the panel used to do all the graphical displaying for the network nodes.
	 */
	JPanel mainView	= new JPanel();
	
	/**
	 * @param splitPanel
	 * <p>This holds both the console panel and the main graphical display panel.
	 */
	JSplitPane splitPanel = null;
	
	/**
	 * @param commandConsole
	 * <pre>This holds a text area accompanied by a text field. The fields contents are output to the test area when the user presses the enter key.</pre>
	 */
	Console commandConsole = null;
	
	/**
	 * public Driver()
	 * <p>This constructor sets up a display including a console window.
	 * <pre>
	 * *-------------*
	 * |             |
	 * |Main Display | <-This displays all the interfaces and links
	 * |             |
	 * *-------------* <-Panel is split here
	 * |Console Text | <-Console text area auto scrolls
	 * *-------------*
	 * |Console Entry| <-Outputs text to console text area
	 * *-------------*</pre>
	 */
	public Driver() {
//		Main = new Thread(new Runnable() {
//			public void run() {
//				
//			}
//		});
		setupLayout();
	}
	
	final private void setupLayout() {
		commandConsole = new Console(true);
		commandConsole.setMinimumSize(new Dimension(0,0));
		
		mainView.addMouseListener(this);
		mainView.addMouseMotionListener(this);
		
		splitPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, mainView, commandConsole);
		splitPanel.setOneTouchExpandable(true);
		splitPanel.setDividerLocation(240);
		splitPanel.setResizeWeight(1.0);
		splitPanel.addKeyListener(commandConsole);
		splitPanel.addMouseListener(this);
		splitPanel.addMouseMotionListener(this);
		

		this.add(splitPanel);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setSize(640, 640);
		//this.pack();
		this.setVisible(true);	
	}
	
	public static void main(String[] args) {
		Driver D = new Driver();
		D.commandConsole.submitEntryReq(Request_Types.LOGIN);
	}
	
	public void paintComponent(Graphics G) {
		// TODO fill out
		super.repaint();
	}

	@Override
	public void mouseDragged(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseMoved(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseClicked(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

}
